function toGib(byte) {
	return (byte / 1.073741824E9).toFixed(2) + ' Gib';
}

$(function () {
	layui.use(['jquery','table','layer'],function () {
		let $ = layui.jquery;
		let layer = layui.layer;
		$.ajax({
			url: '/memory/static',
			type: 'get',
			success: function (data) {
				$.each(data,function (index, value) {
					$(`<blockquote class="layui-elem-quote">内存${index+1}</blockquote><table class="layui-table"><colgroup><col width="20%"></colgroup><thead><tr><td>属性</td><td>值</td></tr></thead><tbody><tr><td>bank标签</td><td class="bankLabel">${value.bankLabel === '' ? '无' : value.bankLabel}</td></tr><tr><td>内存容量</td><td class="capacity">${value.capacity / 1.073741824E9} Gib</td></tr><tr><td>时钟频率</td><td class="clockSpeed">${value.clockSpeed / 1E6} MHz</td></tr><tr><td>制造商</td><td class="manufacturer">${value.manufacturer}</td></tr><tr><td>内存类型</td><td colspan="memoryType">${value.memoryType}</td></tr></tbody></table>`).appendTo($('#container'));
				});
			},
			error: function () {
				layer.msg('出错了');
			}
		});
		function loopGetMessage() {
			$.ajax({
				url: '/memory/dynamic',
				type: 'get',
				success: function (data) {
					$('#physicalTotal').text(toGib(data.physicalTotal));
					$('#physicalFree').text(toGib(data.physicalFree));
					$('#physicalUsed').text(toGib(data.physicalUsed));
					$('#physicalUsage').text((data.physicalUsage * 1E2).toFixed(2) + ' %');
					$('#swapTotal').text(toGib(data.swapTotal));
					$('#swapFree').text(toGib(data.swapFree));
					$('#swapUsed').text(toGib(data.swapUsed));
					$('#swapUsage').text((data.swapUsage * 1E2).toFixed(2) + ' %');
				},
				error: function () {
					layer.msg('出错了');
				}
			});
		};
		loopGetMessage();
		setInterval(loopGetMessage,2000);
	});
});